// Redirect 重定向，也就是路由跳转的组件
import { Route, Redirect } from 'react-router-dom'

import { isAuth } from '../../utils'

const AuthRoute = ({ children, ...rest }) => {
  return (
    <Route
      {...rest}
      render={props => {
        const isLogin = isAuth()
        if (isLogin) {
          return children
        }

        return (
          <Redirect
            to={{
              pathname: '/login',
              state: { from: props.location.pathname }
            }}
          />
        )
      }}
    />
  )
}

export { AuthRoute }
